Skip to content

reset disabled session per SessionSchedule to avoid message loss on Logon#1181

Merged
chrjohn merged 6 commits intoquickfix-j:masterfrom
Ra9huvansh:fix-965-disabled-session-reset
May 6, 2026
Merged

reset disabled session per SessionSchedule to avoid message loss on Logon#1181
chrjohn merged 6 commits intoquickfix-j:masterfrom
Ra9huvansh:fix-965-disabled-session-reset

Conversation

@Ra9huvansh
Copy link
Copy Markdown
Contributor

@Ra9huvansh Ra9huvansh commented Apr 8, 2026

Fixes #965

When a session is disabled (e.g. after calling logout()) and has no active connection, Session.next() was returning early before it could reach the SessionSchedule check. This meant that even if the session schedule said it was time to reset, the reset never happened.

The problem shows up when messages are sent via sendToTarget() to a disabled session. They get queued in the message store and advance the sequence numbers. When next() is called by the internal timer, it hits the early return and exits without resetting, so those queued messages are never cleared. The next time the session connects, method next() is called by the timer thread within a second, resetting the message store and losing the stored messages.

The fix is straightforward. Instead of returning immediately when the session is disabled and not logged on, we now let execution fall through to the session schedule block first, and return after it. The existing state.isResetNeeded() check already handles @philipwhiuk's suggestion of only resetting when sequence numbers have actually advanced beyond 1, so no extra logic was needed there.

Changes:

  • Session.java: removed the early return for the disabled+not-logged-on case in next(), added the guard after the schedule block instead
  • SessionTest.java: added testDisabledSessionIsResetBySchedule which reproduces the exact scenario from the bug report

Tests run:

  • SessionTest — 72/72 passing (includes the new test)
  • Full quickfixj-core test suite — 0 failures, 0 errors

@chrjohn chrjohn changed the title Fix QFJ-965: reset disabled session per SessionSchedule to avoid message loss reset disabled session per SessionSchedule to avoid message loss Apr 8, 2026
@Ra9huvansh
Copy link
Copy Markdown
Contributor Author

Any adjustments to make, happy to help.

@chrjohn
Copy link
Copy Markdown
Member

chrjohn commented May 2, 2026

Not at the moment, slowly working through my backlog. ;) thank you

Comment thread quickfixj-core/src/main/java/quickfix/Session.java Outdated
Co-authored-by: Christoph John <christoph.john@macd.com>
@chrjohn
Copy link
Copy Markdown
Member

chrjohn commented May 3, 2026

@Ra9huvansh
I'll let copilot take a look but don't act on its feedback, I'll let you know.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a QuickFIX/J session lifecycle edge case where disabled (logged-out) sessions could skip SessionSchedule-driven resets, leading to queued messages/sequence number drift and potential message loss on the next reconnect.

Changes:

  • Adjusts Session.next() control flow so the SessionSchedule check can run even when the session is disabled and not logged on.
  • Adds a regression test covering the disabled + disconnected + advanced sequence numbers scenario to ensure scheduled resets still occur.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
quickfixj-core/src/main/java/quickfix/Session.java Moves the disabled+not-logged-on early-return to after the schedule block so scheduled resets can still happen.
quickfixj-core/src/test/java/quickfix/SessionTest.java Adds testDisabledSessionIsResetBySchedule() to reproduce/guard the reported message-loss scenario (issue #965).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chrjohn chrjohn changed the title reset disabled session per SessionSchedule to avoid message loss reset disabled session per SessionSchedule to avoid message loss on Logn May 4, 2026
@chrjohn chrjohn changed the title reset disabled session per SessionSchedule to avoid message loss on Logn reset disabled session per SessionSchedule to avoid message loss on Logon May 4, 2026
Comment thread quickfixj-core/src/main/java/quickfix/Session.java Outdated
Comment thread quickfixj-core/src/test/java/quickfix/SessionTest.java
Comment thread quickfixj-core/src/main/java/quickfix/Session.java Outdated
@chrjohn chrjohn added this to the QFJ 3.0.1 milestone May 6, 2026
@chrjohn
Copy link
Copy Markdown
Member

chrjohn commented May 6, 2026

@Ra9huvansh thank you 👍

@chrjohn chrjohn merged commit 94cd393 into quickfix-j:master May 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling a previously disabled session might lead to message loss

3 participants